package com.hx.base.zzw;

/**
 * @author MinghuaChen
 * @date 2022-03-09 23:56
 * @description
 */
public class Main {
    public static void main(String[] args) {
        System.out.println(licenseKeyFormatting("5F3Z-2e-9-w", 5));
    }

    public static String licenseKeyFormatting(String S, int K) {
        StringBuffer stringBuffer = new StringBuffer();
        S = S.replace("-", "");
        S = S.toUpperCase();
        stringBuffer.append(S);
        int i = S.length() - K;
        while (i > 0) {
            stringBuffer = stringBuffer.insert(i, "-");
            i -= K;
        }
        return stringBuffer.toString();
    }
}
